#!/bin/bash

# install libs & tools
apt-get install ksh gcc wget automake gfortran
apt-get install python python-numpy python-scipy
apt-get install libgctp-dev libtiff5-dev libgeotiff-dev libhdf4-dev libhdfeos-dev libnetcdf-dev libopenjpeg-dev
cd /usr/lib
ln -s libgctp.a libGctp.a

# where our libs are?
export TIFFINC="/usr/include/" # libtiff4-dev
export TIFFLIB="/usr/lib/"
export JPEGINC="/usr/include/" # libopenjpeg-dev
export JPEGLIB="/usr/lib/"
export GEOTIFF_INC="/usr/include/geotiff/" # libgeotiff-dev
export GEOTIFF_LIB="/usr/lib/"
export HDFINC="/usr/include/hdf/" # libhdf4-dev
export HDFLIB="/usr/lib/"
export HDFEOS_INC="/usr/include/" # libhdfeos-dev
export HDFEOS_LIB="/usr/lib/"
export HDFEOS_GCTPINC="/usr/include/gctp/" # libgctp-dev
export HDFEOS_GCTPLIB="/usr/lib/"
export BIN="/usr/bin/"

# our target for ledaps
mkdir /opt/ledaps
cd /opt/ledaps

# get the code from google
svn checkout http://ledaps.googlecode.com/svn/tags/version_1.3.1/ledapsSrc/ ledapsSrc
cd ledapsSrc/src
make
make install
cp lndsrbm/lndsrbm.ksh $BIN
chmod 755 $BIN/lndsrbm.ksh
cd ../..

# get the correction data & tools 
svn checkout http://ledaps.googlecode.com/svn/tags/version_1.3.1/ledapsAncSrc/ ledapsAncSrc                     
wget http://landsat.usgs.gov/espa/files/ledaps_anc_1980-2012.tar.gz
tar -vxzf ledaps_anc_1980-2012.tar.gz
cd ledapsAncSrc
make
mv convert_ozone $BIN
mv ncep_repackage $BIN
export ANC_PATH="/opt/ledaps/LedapsAnc/"
./updatetoms.py -s 2013 -e 2014
./updatencep.py -s 2013 -e 2014

# our target for cfmask
export ESUN="/opt/cfmask/src/"
mkdir /opt/cfmask
cd /opt
svn checkout http://cfmask.googlecode.com/svn/cfmask/tags/version_1.2.1 cfmask
cd cfmask/src
make all 
mv cfmask $BIN
cd ../scripts
cp *.py* $BIN

